package com.i3q360.layui.common.util;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;


public class PageWrapper {
	

	
	public static Pageable defaultPage(){
		
		HttpServletRequest request = HttpKit.getRequest();	
		int limit = Integer.valueOf(request.getParameter("limit"));
		int offset = Integer.valueOf(request.getParameter("offset"));
	    String sort = request.getParameter("sort");
	    String order = request.getParameter("order");
	     
	    if(StringUtils.isEmpty(sort)){
	    	return new PageRequest(offset/limit, limit);
	    } else {
	    	return new PageRequest(offset/limit, limit, Sort.Direction.ASC, order);
	    }
	     
	}
}
